package com.ruoyi.web.controller.tool;

import cn.hutool.crypto.SecureUtil;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.db.domain.RiskResultInfo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.spring.web.json.Json;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: ld
 * @Date: 2024-10-19 23:44
 * @Description:
 * @Version: 1.0
 **/

@Controller
@RequestMapping("/operation")
public class OperationController extends BaseController {

    @Value("${api.jyhHostUrl}")
    private String jyhHostUrl;

    @Value("${api.aesKey}")
    private String apiAesKey;

    private String prefix = "operation";

    @RequiresPermissions("operation:view")
    @GetMapping()
    public String build()
    {
        return prefix + "/operation";
    }


    @RequiresPermissions("operation:checkUser")
    @PostMapping("/checkUser")
    @ResponseBody
    public AjaxResult edit(ModelMap mmap, String mobile, String itemId)
    {
        Map<String, String> map = new HashMap<>();
        map.put("mobileMd5", SecureUtil.md5(mobile));
        map.put("itemId", itemId);
        Map<String, String> reqMap = new HashMap<>();
        reqMap.put("dataContent", SecureUtil.aes(apiAesKey.getBytes()).encryptBase64(JSON.toJSONString(map)));
        String resp =  HttpUtil.createPost(jyhHostUrl + "apisource/apis/test/checkUser").body(JSON.toJSONString(reqMap)).execute().body();
        return AjaxResult.success(JSON.parseObject(resp));
    }


    @RequiresPermissions("operation:refresh")
    @PostMapping("/refresh")
    @ResponseBody
    public AjaxResult refresh(ModelMap mmap)
    {
        Map<String, String> reqMap = new HashMap<>();
        reqMap.put("itemId", "123");
        String resp =  HttpUtil.createPost(jyhHostUrl + "apisource/apis/test/refresh").body(JSON.toJSONString(reqMap)).execute().body();
        return AjaxResult.success(JSON.parseObject(resp));
    }
}
